package alp.starcode.edms.sso.controller;

import alp.starcode.edms.sso.model.vo.UserVo;
import alp.starcode.edms.sso.service.SsoService;
import alp.starcode.edms.framework.base.BaseController;
import alp.starcode.common.web.result.Result;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 登录管理 控制层
 *
 * @author liwang
 * 2023-08-14 09:18
 **/
@Api(tags = "CAS模块-认证相关接口")
@RestController
@RequestMapping("login")
@Validated
public class SsoController extends BaseController {

    /**
     * 登录管理 业务处理类
     */
    @Resource
    private SsoService ssoService;

    @PostMapping("authenticate.do")
    @ApiOperation("用户登录认证")
    @ApiOperationSupport(order = 10)
    public Result<String> authenticate(@RequestParam String username, @RequestParam String password) {
        return Result.success(ssoService.authenticate(username, password));
    }

    @PostMapping("logout.do")
    @ApiOperation("用户登出")
    @ApiOperationSupport(order = 20)
    public Result<String> logout(HttpServletRequest request) {
        return Result.success(ssoService.logout(request));
    }

    @GetMapping("getUserInfo.do")
    @ApiOperation("获取用户信息")
    @ApiOperationSupport(order = 30)
    public Result<UserVo> getUserInfo(HttpServletRequest request) {
        return Result.success(ssoService.getUserInfo(request));
    }
}